package com.example.wan1.data;

import com.example.wan1.model.common.CommonResBody;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/***
 * 创建时间：2020/5/2 17:07
 * 创建人：10850
 * 功能描述：观察者的一个简单的封装
 */
public abstract class IsNotObserver implements Observer {

    public abstract void onSuccess(int code, String result);

    public abstract void onFailure(Throwable e, String errorMsg);


    @Override
    public void onSubscribe(Disposable d) {

    }

    @Override
    public void onNext(Object o) {
        CommonResBody t = (CommonResBody) o;
        if (t.getErrorCode() != 0) {
            onFailure(new Exception("出现异常！"), "出现异常！");
        } else {
            onSuccess(t.getErrorCode(), t.getErrorMsg());
        }
    }

    @Override
    public void onComplete() {

    }

    @Override
    public void onError(Throwable e) {
        onFailure(e, e.getMessage());
    }
}

